package com.isoft.src.main.java.model;

import java.util.HashMap;
import java.util.Map;

public class Cart {
    private Map<Product, Integer> items = new HashMap<>();

    public void addProduct(Product product, int quantity) {
        items.put(product, items.getOrDefault(product, 0) + quantity);
    }

    public void removeProduct(Product product) {
        items.remove(product);
    }

    public void clear() {
        items.clear();
    }

    public double getTotalPrice() {
        return items.entrySet().stream()
                .mapToDouble(entry -> entry.getKey().getPrice() * entry.getValue())
                .sum();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Cart:\n");
        items.forEach((product, quantity) ->
                sb.append(String.format("%s x %d\n", product, quantity))
        );
        sb.append(String.format("Total Price: %.2f\n", getTotalPrice()));
        return sb.toString();
    }

    public void add(Product product) {

    }

    public boolean isEmpty() {
        if ()
    }
}
